

import basePanleScript from "../base/basePanleScript";
import gameModel from "./gameScene/gameModel";

const { ccclass, property } = cc._decorator;

enum changeType{
    sceneBg=1,
    btnBg=2
}
// enum bgType{
//     back=0,
//     font=1,
// }
const colorArr=[
    [[208,75,87,255],[18,65,108,255],[65,108,109,255],[200,201,118,255],[244,153,65,255]],
    [[18,54,73,255],[65,108,109,255],[200,201,118,255],[244,153,65,255],[208,75,87,255]],
]

const btnColorArr=[
    [[240,66,140,160.65],[80,255,187,160.65],[153,237,7,178.5],[162,255,0,204],[255,245,0,204]],
    [[255,255,255,255],[255,255,255,255],[255,255,255,255],[255,255,255,255],[255,255,255,255]],
]

const time=5;

@ccclass
export default class bg_change extends basePanleScript {
    public onLoaded(param: any): void {
        // throw new Error("Method not implemented.");
    }
    public onEnter(param: any): void {
        // throw new Error("Method not implemented.");
    }
    public onRefresh(param: any): void {
        // throw new Error("Method not implemented.");
    }
    @property
    changeType:changeType=changeType.sceneBg;

    // @property
    // bgType:bgType=null;


    // private colorNum:number=0;
    private back;
    private font;

    changeColor(data,s){
        var arr
        if(this.changeType==changeType.sceneBg){
            arr=colorArr;
        }else{
            arr=btnColorArr;
        }

        // this.colorNum%=colorArr[0].length;
        var changerColorAction = cc.tintTo(time,
            arr[0][data][0],
            arr[0][data][1],
            arr[0][data][2]
        );
        var changerFronColorAction = cc.tintTo(time,
            arr[1][data][0],
            arr[1][data][1],
            arr[1][data][2]
        );
        // //this.node.opacity=this.BgColor[this.colorNum].a/100*255;
        this.back.runAction(changerColorAction);
        this.font.runAction(changerFronColorAction);
        // this.colorNum++;
    }
    handler(data){
        // var self=this;
        // console.error("变颜色",data.content,self)
        switch(data.type){
            case "changeColor":
            this.changeColor(data.content,this);
            break;
        }

    }

    onEnable(){
        // this.self=this;
        this.back=this._get_("back");
        this.font=this._get_("font");
        // this.changeColor(gameModel.getInstance().ColorType,this);
        let colorN=gameModel.getInstance().ColorType;
        var arr
        if(this.changeType==changeType.sceneBg){
            arr=colorArr;
        }else{
            arr=btnColorArr;
        }
        this.back.color=cc.color(arr[0][colorN][0],arr[0][colorN][1],arr[0][colorN][2]);
        this.font.color=cc.color(arr[1][colorN][0],arr[1][colorN][1],arr[1][colorN][2]);
        (<any>window).CustomEventManager.bind("changeColor",this);
    }

    onDisable(){
        (<any>window).CustomEventManager.unBind("changeColor",this);
    }
}
